﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using bzxxxt.bll;

namespace bzxxxt.admin.ashx
{
    /// <summary>
    /// bg_hzBaseSectionBy 的摘要说明
    /// </summary>
    public class bg_hzBaseSectionBy : rm_base
    {
        HzBLL hzBLL = new HzBLL();
        public override void getall(HttpContext context)
        {
            
            string strpid = context.Request.Params["paradiseid"];
            if (string.IsNullOrEmpty(strpid)) strpid = "0";
            int pid = int.Parse(strpid);
            var p = hzBLL.getParadise(pid);
            string pcode = "0";
            if (p != null) pcode = p.code;
            string json = hzBLL.hzBaseSectionByUserParadise(pcode);
            context.Response.Write(json);

        }

        public override void other(HttpContext context)
        {
            string action = context.Request.Params["action"];
            switch (action)
            {
                case "export":
                    {
                        string strpid = context.Request.Params["paradiseid"];
                        if (string.IsNullOrEmpty(strpid)) strpid = "0";
                        int pid = int.Parse(strpid);
                        var p = hzBLL.getParadise(pid);
                        string pcode = "0";
                        string pname = "";
                        if (p != null){
                            pcode = p.code;
                            pname = p.name.Trim();
                        }
                        HttpResponse resp = context.Response;
                        resp.Charset = "utf-8";
                        resp.Clear();
                        string filename = "【" + pname + "】基本情况汇总表_" + DateTime.Now.ToString("yyyyMMddHHmmss");
                        resp.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
                        resp.ContentEncoding = System.Text.Encoding.UTF8;

                        resp.ContentType = "application/ms-excel";
                        string style = "<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=utf-8\"/>"
                            + "<style> .table{ font: 13pt Tahoma, Verdana; color: #000000; text-align:center;border-collapse:collapse;border:solid #000 1px; } "
                            + ".table td{text-align:center; border:solid #000 1px;} "
                            + ".table th{text-align:center; font-weight: bold; padding:5px; border:solid #000 1px;} </style>";
                        resp.Write(style);

                        resp.Write("<table class='table' border='1'><tr><th colspan='10' >【" + pname + "】基本情况汇总表</th></tr><tr><th>名称</th><th>号码总数</th><th>已存号总数</th><th>空号总数</th><th>单穴总数</th><th>双穴总数</th><th>多穴总数</th><th>总穴数</th><th>死者穴数</th><th>空穴数</th></tr>");
                        var list = hzBLL.GetHzBaseSectionByUserParadise(pcode);
                        for (int i = 0; i < list.Count(); i++)
                        {
                            string row = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td><td>{9}</td></tr>",
                                list[i].pname, list[i].totalgraves, list[i].occupygraves, list[i].emptygraves, list[i].singlegraves, list[i].doublegraves, list[i].multigraves, list[i].totaldeads, list[i].storedeads, list[i].emptydeads);
                            resp.Write(row);
                        }
                        resp.Write("</table>");
                        resp.Flush();
                        break;
                    }
            }
        }
    }
}